package cn.edu.njust.alg.leetcode;

/**
 * 创建时间：2015年6月15日 上午11:47:37 项目名称：AlgorithmExercise
 * 
 * @author Zhou Xiumin
 * @version 1.0
 * @since JDK 1.7.0_21 文件名称：Leetcode_0_t.java 类说明：
 */
public class Leetcode_83_Remove_Duplicates_from_Sorted_List {

	public static ListNode deleteDuplicates(ListNode head) {
		if (head == null) {
			return head;
		}
		ListNode p, pre;
		pre = null;
		p = head;
		while (p != null) {
			if (pre != null && pre.val == p.val) {
				p = p.next;
				pre.next = p;
				continue;
			} else {
				pre = p;
				p = p.next;
			}
		}
		return head;
	}

	public static void main(String[] args) {
		ListNode A1 = new ListNode(1);
		ListNode A2 = new ListNode(1);
		ListNode A3 = new ListNode(2);
		A1.next = A2;
		A2.next = A3;

		ListNode head = deleteDuplicates(A1);
		ListNode p = head;
		while (p != null) {
			System.out.print(p.val + " ");
			p = p.next;
		}

	}

}
